//
//  HWQuestionsViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2021/7/8.
//  Copyright © 2021 Chendaobin. All rights reserved.
//

#import "HWQuestionsViewController.h"
#import "HWQuestionsCollectionViewCell.h"
#import "HWSelecTtitleTableViewCell.h"
#import "HWAnswerModel.h"

@interface HWQuestionsViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic)UIImageView *beijingImageView;
@property(strong,nonatomic)UIImageView *riqibeijingImageView;
@property(strong,nonatomic) UICollectionView *maincollectionView;
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic)UILabel *jingriqudalabel;
@property(strong,nonatomic)UIView *headeView;
@property(strong,nonatomic)UILabel *cumulativeLabel;
@property(strong,nonatomic)UILabel *titleLabel;
@property(strong,nonatomic)UIButton *xiazaibutton;
@property(strong,nonatomic)UIImageView *cuowuAndzhenQuImageView;
@property(strong,nonatomic)UIImageView *chenggongbianshiImageView;
@property(strong,nonatomic)NSMutableArray *riliArray;
@property(strong,nonatomic)NSMutableDictionary *MyDic;
@property(strong,nonatomic)NSDictionary *answerDic;
@property(strong,nonatomic) HWAnswerModel *answerModel;
// @property(strong,nonatomic) NSIndexPath *seleIndex;
@property(strong,nonatomic)HWSelecTtitleTableViewCell *xuanzhongCell;





@end

@implementation HWQuestionsViewController


-(UITableView *)mainaTableVie {

    if (_mainaTableVie == nil
        ) {


        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 438) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
    


    }
    return   _mainaTableVie ;
}


-(void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
}

-(void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 设置常用的属性
    [self settingCommonProperties];
    // 设置UI
    [self setupUI];
    //设置导航栏
    [self navigaView];
    // 设置
    [self setupcontionView];
    // 设置UitableView
    [self  setuptableView];
    
    // 设置tabeleView 的 header
    [self setuphederView];
    
    // 设置tabelViewFooterview
    [self addfootView];
    // 发送网络请求
    [self sendTheRequestData];
    
    
}

// 发送请求
- (void)sendTheRequestData {
    
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
    NSDictionary *parametes = @{
                                @"ct" :  @"app",
                                @"ac" : @"answer",
                                @"ios" : @"1",
                                @"uid" :userID,
                                @"t" :tStr,
                                @"sign": signMD5
                                };
    
    
  //   [MBProgressHUD show:@"正在刷新"];
    
    [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
        
      
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
     //   [MBProgressHUD hideHUD];
        
        
        if ([codeStr intValue] == 1) {
         
          //  self.fenleiMuArr = [response[@"data"] mutableCopy];
          //   [MBProgressHUD  showError:@"加载成功"];
            self.riliArray =  [response[@"rili"] mutableCopy];
            self.MyDic = [response[@"my"]  mutableCopy];
            self.answerDic = response[@"answer"];
            self.answerModel = [HWAnswerModel mj_objectWithKeyValues:response[@"answer"]];
    
            [self refreshtheInterfaceView];
            
            
            

        } else {
            
           //   [MBProgressHUD  showError:@"加载失败"];
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
      
        [MBProgressHUD  showError:@"加载失败"];
        
    }];
    
    
    
    
    
    
}

// 刷新界面
- (void)refreshtheInterfaceView{

    [self.maincollectionView reloadData];
    
    NSIndexPath *indexPath = [NSIndexPath  indexPathForRow:self.riliArray.count-1 inSection:0];
    [self.maincollectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionRight animated:NO];
    
    
   //  self.jingriqudalabel.text = @"今日趣味问答（+0.5）";
 //    self.cumulativeLabel.text = @"恭喜您，本月已累计获得奖励19.9平台币，快去使用吧～";
    self.jingriqudalabel.text = [NSString stringWithFormat:@"今日趣味问答(+%@)",self.MyDic[@"number"]];
    self.cumulativeLabel.text = [NSString stringWithFormat:@"恭喜您，本月已累计获得奖励%@%@，快去使用吧～",self.MyDic[@"total"],self.MyDic[@"type"]];
    
    self.titleLabel.text = [NSString stringWithFormat:@"%@",self.answerDic[@"name"]];
 
    NSString  *today_answer = [NSString stringWithFormat:@"%@",self.MyDic[@"today_answer"]];
    self.xiazaibutton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    
   // 今日是否已答题，0 未答题，1 已答题 , 2 回答错误
    if ([today_answer intValue] == 0 ) {
        
        self.chenggongbianshiImageView.hidden = YES;
//        self.xiazaibutton.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView:self.xiazaibutton kaish:RGB(254, 151, 134) endjishu:RGB(253, 116, 94)];
        self.xiazaibutton.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView:self.xiazaibutton kaish:RGB(251, 234, 159) endjishu:RGB(254, 216, 154)];
        
        [self.xiazaibutton setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
        
    } else if ([today_answer intValue] == 1) {
        self.chenggongbianshiImageView.hidden = NO;
        self.chenggongbianshiImageView.image = [UIImage imageNamed:@"mubiaowanchnenico"];
//        self.xiazaibutton.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView:self.xiazaibutton kaish:RGB(254, 151, 134) endjishu:RGB(253, 116, 94)];
        self.xiazaibutton.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView:self.xiazaibutton kaish:RGB(246,  218, 74) endjishu:RGB(253, 180, 64)];
        [self.xiazaibutton setTitle:@"恭喜你，回答正确" forState:UIControlStateNormal];
        [self.xiazaibutton setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
        
        
        
    }else if([today_answer intValue] == 2) {
        
        self.chenggongbianshiImageView.hidden = NO;
      //  self.chenggongbianshiImageView.image = [UIImage imageNamed:@"henyihanshibaile"];
        self.chenggongbianshiImageView.image = [UIImage imageNamed:@"xingyaoyihang"];
      //  self.xiazaibutton.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView:self.xiazaibutton kaish:RGB(254, 151, 134) endjishu:RGB(253, 116, 94)];
        self.xiazaibutton.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView:self.xiazaibutton kaish:RGB(246,  218, 74) endjishu:RGB(253, 180, 64)];
        [self.xiazaibutton setTitle:@"别灰心，明天再来试试吧" forState:UIControlStateNormal];
        [self.xiazaibutton setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
        
    }
    
    
    [self.mainaTableVie reloadData];
    
    
    
    
}













// 设置常用的属性
- (void)settingCommonProperties {
    self.view.backgroundColor = [UIColor whiteColor];
    // self.view.backgroundColor = RGB(255, 150, 83);
    
    self.view.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView: self.view kaish:RGB(73, 74, 86) endjishu:RGB(32, 32, 42)];
    
    
}
// 设置导航栏
- (void)navigaView  {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(10,StatusBarHeight, 40, 44);
    // button.backgroundColor = [UIColor redColor];
    [button setImage:[UIImage imageNamed:@"details_back"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
    
    UILabel *textlabel = [[UILabel alloc]initWithFrame:CGRectMake((kScreenW-70)/2, StatusBarHeight, 70, 44)];
    textlabel.text = @"每日答题";
    textlabel.textAlignment =  NSTextAlignmentCenter;
    textlabel.textColor = [UIColor whiteColor];
    textlabel.font = [UIFont systemFontOfSize:16];
    [self.view addSubview:textlabel];
    

}

// 返回上一个界面
- (void)buttonTap {
    
    [self.navigationController popViewControllerAnimated:YES];

    
}

// 设置常用的UI
- (void)setupUI {
    
    self.beijingImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CFLScaleValue*375, CFLScaleValue*230)];
    self.beijingImageView.image = [UIImage imageNamed:@"xingyaodantijiemi"];
    [self.view addSubview:self.beijingImageView];
    
    self.riqibeijingImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.beijingImageView.bottom-40, kScreenW, 83)];
   //  self.riqibeijingImageView.image = [UIImage imageNamed:@"dizhangbeijingtu"];
    self.riqibeijingImageView.image = [UIImage imageNamed:@"xingyaojuxingtupian"];
  
    self.riqibeijingImageView.userInteractionEnabled = YES;
    [self.view addSubview:self.riqibeijingImageView];
    
    UIImageView *xingyaoimageview = [[UIImageView alloc]initWithFrame:CGRectMake(0,  self.riqibeijingImageView.bottom+0, kScreenW, 47)];
   //  xingyaoimageview.image = [UIImage imageNamed:@"xingyaoxunzhongshitu"];
    UIImage   *image1 =  [UIImage imageNamed:@"xingyaoxunzhongshitu"];
    UIImage   *image2 =  [image1 resizableImageWithCapInsets:UIEdgeInsetsMake(image1.size.height*0.5, image1.size.width*0.5, image1.size.height*0.5, image1.size.width*0.5)];
    xingyaoimageview.image = image2;
    [self.view addSubview:xingyaoimageview];
    
    
    
    
    
}
// 添加常用的控件
- (void)setupcontionView {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
 //   CGFloat jianju =  (kScreenW - 78*CFLScaleValue*4 -20) / 3;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    
    self.maincollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(12, 13,  kScreenW-24,10+35+6+17) collectionViewLayout:layout];
    self.maincollectionView.showsHorizontalScrollIndicator = NO;
    self.maincollectionView.delegate = self;
    self.maincollectionView.dataSource = self;
    self.maincollectionView.backgroundColor = [UIColor clearColor];
  //  self.maincollectionView.backgroundColor = RGB(217, 247, 250);
    //self.maincollectionView.alwaysBounceHorizontal = YES;
    
    
   // self.maincollectionView.contentInset = UIEdgeInsetsMake(0, 10, 0, 10);
    // [self.maincollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];  //  一定要设置
    [self.maincollectionView registerClass:[HWQuestionsCollectionViewCell class] forCellWithReuseIdentifier:@"cellID"];
   // [self.maincollectionView  registerNib:[UINib nibWithNibName:@"HWShouYouCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cellID"];
    
    //  [UINib nibWithNibName:@"HWShouYouCollectionViewCell" bundle:nil]
    
    self.maincollectionView.userInteractionEnabled = YES;
    [self.riqibeijingImageView  addSubview:self.maincollectionView];
    

    
}

// 设置uitableView
- (void)setuptableView {
    
    self.mainaTableVie.frame = CGRectMake(0, self.riqibeijingImageView.bottom+20+47-20, kScreenW, 360);
    self.mainaTableVie.layer.cornerRadius = 5;
    self.mainaTableVie.layer.masksToBounds = YES;
   //  self.mainaTableVie.backgroundColor = RGB(254, 240, 229);
    self.mainaTableVie.backgroundColor = RGB(255, 255, 255);
    [self.view addSubview:self.mainaTableVie];
    
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenW-300)/2, self.riqibeijingImageView.bottom+20-15+47, 300, 30)];
 //    imageView.image =
    UIImage   *image1 =  [UIImage imageNamed:@"jinriquweidati"];
    UIImage   *image2 =  [image1 resizableImageWithCapInsets:UIEdgeInsetsMake(image1.size.height*0.5, image1.size.width*0.5, image1.size.height*0.5, image1.size.width*0.5)];
    imageView.image = image2;
    [self.view addSubview:imageView];
    
    imageView.hidden = YES;
//    self.jingriqudalabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 280, 30)];
//    self.jingriqudalabel.text = @"今日趣味问答（+0.5）";
//    self.jingriqudalabel.textAlignment =  NSTextAlignmentCenter;
//    self.jingriqudalabel.textColor = [UIColor whiteColor];
//    self.jingriqudalabel.font = [UIFont systemFontOfSize:16];
//    [imageView addSubview:  self.jingriqudalabel];
//

    
}


// 设置 headeview
- (void)setuphederView {
    
    self.headeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 34+35+35)];
   //  self.headeView.backgroundColor = RGB(254, 240, 229);
    self.headeView.backgroundColor = RGB(255, 255, 255);
    self.mainaTableVie.tableHeaderView = self.headeView;
    
    
    UIView *xuanzeView1 = [[UIView alloc]initWithFrame:CGRectMake(60, 9, 26, 23)];
    [self.headeView addSubview:xuanzeView1];
    
    UIView *zuobianView = [[UIView alloc] initWithFrame:CGRectMake(0, 8.5, 6, 6)];
    zuobianView.layer.cornerRadius = 3;    zuobianView.layer.masksToBounds = YES;
    zuobianView.backgroundColor = RGB(127, 127, 127);
    [xuanzeView1 addSubview:zuobianView];
    
    
    UIView *zuobianView2 = [[UIView alloc] initWithFrame:CGRectMake(16, 6.5, 10, 10)];
    zuobianView2.layer.cornerRadius = 5;    zuobianView2.layer.masksToBounds = YES;
    zuobianView2.backgroundColor = RGB(63, 64, 74);
    [xuanzeView1 addSubview:zuobianView2];
    
    UIView *yobianxuanzeView1 = [[UIView alloc]initWithFrame:CGRectMake(kScreenW-60-26, 9, 26, 23)];
    [self.headeView addSubview:yobianxuanzeView1];
    
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(16, 8.5, 6, 6)];
    rightView.layer.cornerRadius = 3;    rightView.layer.masksToBounds = YES;
    rightView.backgroundColor = RGB(127, 127, 127);
    [yobianxuanzeView1 addSubview:rightView];
    
    
    UIView *rightView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 6.5, 10, 10)];
    rightView2.layer.cornerRadius = 5;    rightView2.layer.masksToBounds = YES;
    rightView2.backgroundColor = RGB(63, 64, 74);
    [yobianxuanzeView1 addSubview:rightView2];
    
    
    self.jingriqudalabel = [[UILabel alloc]initWithFrame:CGRectMake(60+23, 9, kScreenW-60-23-60-23, 23)];
    self.jingriqudalabel.text = @"今日趣味问答（+0.5）";
    self.jingriqudalabel.textAlignment =  NSTextAlignmentCenter;
  //   self.jingriqudalabel.textColor = [UIColor whiteColor];
    self.jingriqudalabel.textColor = RGB(63, 64, 75);
    self.jingriqudalabel.font = [UIFont systemFontOfSize:16];
    [ self.headeView  addSubview:  self.jingriqudalabel];
    

    
    
    
    
    
    
    
    
    
    
    self.cumulativeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 34, kScreenW-20, 14)];
    self.cumulativeLabel.text = @"恭喜您，本月已累计获得奖励19.9平台币，快去使用吧～";
    self.cumulativeLabel.textAlignment =  NSTextAlignmentCenter;
    self.cumulativeLabel.textColor = RGB(70, 70, 82);
    self.cumulativeLabel.font = [UIFont systemFontOfSize:10];
    [self.headeView  addSubview: self.cumulativeLabel];
    
    UIView *fengexiangView = [[UIView alloc]initWithFrame:CGRectMake(12,  self.cumulativeLabel.bottom+5, kScreenW-24, 1)];
    fengexiangView.backgroundColor = RGB(240, 240, 240);
    [self.headeView addSubview:fengexiangView];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, fengexiangView.bottom+14, kScreenW-20, 40)];
    self.titleLabel.text = @"北京的首都是？";
    self.titleLabel.textAlignment =  NSTextAlignmentLeft;
    self.titleLabel.textColor = RGB(51, 51, 51);
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.numberOfLines = 2;
    [self.headeView  addSubview:  self.titleLabel];
    
    
    self.chenggongbianshiImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW-125, 20, 125, 123)];
    self.chenggongbianshiImageView.image = [UIImage imageNamed:@"wanchengbiaoqinaico"];
    [self.headeView addSubview:self.chenggongbianshiImageView];
    
    
    
}

// 添加footview
- (void)addfootView {
    
    
    
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW , 49+30+40)];
  //   footView.backgroundColor = RGB(254, 240, 229);
    footView.backgroundColor = RGB(255, 255, 255);
    self.mainaTableVie.tableFooterView = footView ;
    
    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(42, 39, kScreenW-42*2, 30) Title:@"提交" Image:nil Font:14 Color:RGB(255, 255, 155) Target:self Selector:@selector(tijiaoTap)];
    self.xiazaibutton = butt;
    butt.backgroundColor = RGB(38, 154, 255);
    butt.layer.cornerRadius = 15;
    butt.layer.masksToBounds = YES;
    butt.backgroundColor = [UIColor  bm_colorGradientChangeWithSizeView:butt kaish:RGB(254, 151, 134) endjishu:RGB(253, 116, 94)];
    
    [footView addSubview:butt];
    
    
//    self.chenggongbianshiImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW-125, -10, 125, 123)];
//    self.chenggongbianshiImageView.image = [UIImage imageNamed:@"wanchengbiaoqinaico"];
//    [footView addSubview:self.chenggongbianshiImageView];
    
    
    
    
    

    
}


#pragma mark --------- 点击提交按钮

- (void)tijiaoTap {
    
    NSString  *today_answer = [NSString stringWithFormat:@"%@",self.MyDic[@"today_answer"]];

   // 今日是否已答题，0 未答题，1 已答题 , 2 回答错误
    if ([today_answer intValue] == 0 ) {
        
        if (self.xuanzhongCell == nil) {
            
            [MBProgressHUD showError:@"请选择答案"];
            return;
        }
        NSIndexPath *index =   [self.mainaTableVie indexPathForCell:self.xuanzhongCell];
       //  [MBProgressHUD show:@"正在提交"];
        
        NSString *option = @"";
        
        if (index.row == 0) {
            
            option = @"optiona";
             
        }else if (index.row == 1) {
            
            option = @"optionb";
        }else if (index.row == 2) {
            
            option = @"optionc";
            
        } else if(index.row == 3) {
            
            option = @"optiond";
            
            
        }
        
        
        NSString *userID = [HWLocallyStoredData getLoginUserID];
        NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
        NSString *sign = [NSString stringWithFormat:@"%@%@%@%@",userID,self.answerModel.id,option,@"fsd213ewdsadqwe2121213edsad"];
        NSString *signMD5 = [WMUtil md5HexDigest:sign];
        NSDictionary *parametes = @{
                                    @"ct" :  @"app",
                                    @"ac" : @"answer_submit",
                                    @"ios" : @"1",
                                    @"uid" :userID,
                                    @"id": self.answerModel.id,
                                    @"option" :option,
                                    @"sign": signMD5
                                    };
        
        

        
        [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
            
          
            NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
          
            
            // [MBProgressHUD hideHUD];
            
          //  [self performSelector:@selector(testMethod1) withObject:@"aaa" afterDelay:1];
            
          //   [self sendTheRequestData];
            
            if ([codeStr intValue] == 1) {
             
              //     [MBProgressHUD  showError:@"提交成功"];
                //   [self sendTheRequestData];
              
             //    self.MyDic[@"today_answer"] = @""
                
                
                [self.MyDic setValue:[NSString stringWithFormat:@"%@",response[@"data"][@"status"]] forKey:@"today_answer"];
               //  self.MyDic[@"number"]
    
                [self.MyDic setValue:[NSString stringWithFormat:@"%@",response[@"data"][@"total"]] forKey:@"total"];
                [self.MyDic setValue:[NSString stringWithFormat:@"%@",response[@"data"][@"jiangli"]] forKey:@"number"];
                
                self.answerModel.true1= [NSString stringWithFormat:@"%@",response[@"data"][@"true"]];
                
                self.answerModel.submit = [NSString stringWithFormat:@"%@",response[@"data"][@"submit"]];
                
                
                NSMutableDictionary *dic1 = [self.riliArray[self.riliArray.count-1] mutableCopy];
                
              //   answer_status answer_title
                [dic1 setValue:[NSString stringWithFormat:@"%@",response[@"data"][@"status"]] forKey:@"answer_status"];
                NSString *status = [NSString stringWithFormat:@"%@", response[@"data"][@"status"]];
                if ([status intValue] == 1) {
                    
                    [dic1 setValue:[NSString stringWithFormat:@"%@",response[@"data"][@"jiangli"]] forKey:@"answer_title"];
                    
                } else if ( [status intValue] == 2) {
                    
                    [dic1 setValue:[NSString stringWithFormat:@"%@",@"错误"] forKey:@"answer_title"];
                }
                
            
                [self.riliArray removeLastObject];
                
                [self.riliArray addObject:dic1];
                
                
                
                [self.mainaTableVie reloadData];
                [self refreshtheInterfaceView];
                
                

            } else {
                
               //   [MBProgressHUD  showError:@"加载失败"];
                 [self sendTheRequestData];
                
            }
            NSLog(@"%@",response);
            
            
        } failure:^(NSString *error) {
          
            [MBProgressHUD  showError:@"加载失败"];
            
            
            
        }];
        
        
        
        
        
        
        
        
    
    }
    
    
    
    
}


-(void)testMethod1 {
    
    [self sendTheRequestData];
    
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.riliArray.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HWQuestionsCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
    NSDictionary *dic = self.riliArray[indexPath.row];
    
    cell.dataDic = dic;
    
    
    
    cell.backgroundColor = [UIColor clearColor];
    
    return cell;
    
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(35+28, 10+35+6+17);
}





#pragma mark  ----  UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    
    
    return  4 ;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  {
    
    return  28+14;
    
    
}





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString  *cellID = @"cellID";
    
    HWSelecTtitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[HWSelecTtitleTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    
    
    if (indexPath.row == 0 ) {
        
        cell.biaotilabel.text =  self.answerModel.optiona;
        
    
        
    
        
        
    } else if (indexPath.row == 1) {
        
        cell.biaotilabel.text =  self.answerModel.optionb;
        
    } else if (indexPath.row == 2) {
        
        cell.biaotilabel.text =  self.answerModel.optionc;
        
    } else {
        cell.biaotilabel.text =  self.answerModel.optiond;
        
    }
//     cell.biaotilabel.text
 //     cell.backgroundColor = RGB(254, 240, 229);
    
     cell.contentView.backgroundColor = RGB(255, 255, 255);
    
    NSString  *today_answer = [NSString stringWithFormat:@"%@",self.MyDic[@"today_answer"]];
    
    cell.ringbianButton.hidden = YES;
    
    

   // 今日是否已答题，0 未答题，1 已答题 , 2 回答错误
    if ([today_answer intValue] == 0 ) {
        
        
        UITapGestureRecognizer *beijingTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(xuanzhong:)];
        [cell.beijingyanSeView addGestureRecognizer:beijingTap];
        
        cell.backgroundColor = RGB(255, 255, 255);
        
    } else if ([today_answer intValue] == 1) {
        
        if ([self.answerModel.true1 isEqualToString:@"optiona"]) {
            
            if (indexPath.row == 0) {
                
                
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
                
            }
            
        } else if ([self.answerModel.true1 isEqualToString:@"optionb"] ) {
            
            
            if (indexPath.row == 1) {
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
                
            }
        } else if ([self.answerModel.true1 isEqualToString:@"optionc"] ) {
            
            
            if (indexPath.row == 2) {
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
                
            }
        } else if ([self.answerModel.true1 isEqualToString:@"optiond"] ) {
            
            
            if (indexPath.row == 3) {
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
            }
            
            
            
        }
        
        
        
        
        
        
  
    }else if([today_answer intValue] == 2) {
        
        if ([self.answerModel.submit isEqualToString:@"optiona"]) {
            
            if (indexPath.row == 0) {
                
                cell.beijingyanSeView.backgroundColor = RGB(254, 175, 161);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"xuanzecuowu"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"回答错误" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"cuwudeico"];
                
            }
            
        } else if ([self.answerModel.submit isEqualToString:@"optionb"] ) {
            
            
            if (indexPath.row == 1) {
                
                cell.beijingyanSeView.backgroundColor = RGB(254, 175, 161);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"xuanzecuowu"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"回答错误" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"cuwudeico"];
                
            }
        } else if ([self.answerModel.submit isEqualToString:@"optionc"] ) {
            
            
            if (indexPath.row == 2) {
                
                
                cell.beijingyanSeView.backgroundColor = RGB(254, 175, 161);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"xuanzecuowu"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"回答错误" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"cuwudeico"];
            }
        } else if ([self.answerModel.submit isEqualToString:@"optiond"] ) {
            
            
            if (indexPath.row == 3) {
                
                
                cell.beijingyanSeView.backgroundColor = RGB(254, 175, 161);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"xuanzecuowu"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"回答错误" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"cuwudeico"];
                
                
            }
            
            
            
        }
        
        
        if ([self.answerModel.true1 isEqualToString:@"optiona"]) {
            
            if (indexPath.row == 0) {
                
                
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
                
            }
            
        } else if ([self.answerModel.true1 isEqualToString:@"optionb"] ) {
            
            
            if (indexPath.row == 1) {
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
                
            }
        } else if ([self.answerModel.true1 isEqualToString:@"optionc"] ) {
            
            
            if (indexPath.row == 2) {
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
                
            }
        } else if ([self.answerModel.true1 isEqualToString:@"optiond"] ) {
            
            
            if (indexPath.row == 3) {
                cell.beijingyanSeView.backgroundColor = RGB(219, 242, 209);
                [cell.ringbianButton setImage:[UIImage imageNamed:@"zhengquduigou"] forState:UIControlStateNormal];
                [cell.ringbianButton  setTitle:@"正确答案" forState:UIControlStateNormal];
                cell.ringbianButton.hidden = NO;
                cell.biaoqianImageView.image = [UIImage imageNamed:@"diyigezhengqudananico"];
            }
            
            
            
        }
        
        
        
        
      
    }

   
    return  cell;
    
    
}

// 点击事件
- (void)xuanzhong:(UITapGestureRecognizer *)sender {
    
    UIView  *view =        sender.view;
    
    NSLog(@"%@",[[view superview] superview]);
    
    NSString  *today_answer = [NSString stringWithFormat:@"%@",self.MyDic[@"today_answer"]];

   // 今日是否已答题，0 未答题，1 已答题 , 2 回答错误
    if ([today_answer intValue] == 0 ) {
        
        HWSelecTtitleTableViewCell *cell = (HWSelecTtitleTableViewCell *)[[view superview] superview];
       //  NSIndexPath *index =   [self.mainaTableVie indexPathForCell:cell];
        
        self.xuanzhongCell.beijingyanSeView.backgroundColor =  RGB(240, 240, 240);
        self.xuanzhongCell.biaoqianImageView.image = [UIImage imageNamed:@"xingyaoweixuanzhongyuanquan"];
     
        self.xuanzhongCell = cell;
        self.xuanzhongCell.beijingyanSeView.backgroundColor = RGB(215, 215, 215);
        self.xuanzhongCell.biaoqianImageView.image = [UIImage imageNamed:@"xingyapicoxuanhzong"];
        
    
    }
    
   
   
    
    
    
    
    
    
}










@end
